# Contributor: Justin Berthault <justin.berthault@zaclys.net>
# Contributor: fossdd <fossdd@pwned.life>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=blocky
# Also update documentation links in blocky.example.yml
pkgver=0.23
pkgrel=3
pkgdesc="DNS proxy as ad-blocker for local network"
pkggroups="blocky"
pkgusers="blocky"
url="https://github.com/0xERR0R/blocky"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install $pkgname.pre-upgrade $pkgname.post-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/0xERR0R/blocky/archive/v$pkgver.tar.gz
	busybox-date.patch
	blocky.initd
	blocky.confd
	blocky.example.yml
	"
# fail with new go for some reason, even with tzdata/goroot
options="!check net"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make VERSION=$pkgver build
}

check() {
	make test
}

package() {
	install -Dvm755 bin/blocky -t "$pkgdir"/usr/bin/
	install -Dvm755 "$srcdir"/blocky.initd "$pkgdir"/etc/init.d/blocky
	install -Dvm644 "$srcdir"/blocky.confd "$pkgdir"/etc/conf.d/blocky
	install -Dvm644 "$srcdir"/blocky.example.yml "$pkgdir"/etc/blocky/config.example.yml

	# blocky will not start if its log directory is missing
	install -dvm750 -o blocky -g blocky "$pkgdir"/var/log/blocky
}

sha512sums="
22431da4c2f259411b7eb790e8f05a7264d0aa96fe4774722bbe71cf9459a3ed7f434b4b295c95b80f2efc6de55ff645f860443838fe793bc413d74b77e395be  blocky-0.23.tar.gz
2f1e60037229ad2730f3d51a16e79f0ef93baf80fa73948d08d1216de5db454f10ea4081558f1c86db2e394948cfce62af20b802278dd89241b591e77bce8b4c  busybox-date.patch
d5507cedb0dab49c139ab4366d3b6428b23c8aa891a7f7d6caad567cfca53f8434f055d4c15d03899712b164a5f2a9e00e9df75ab0e428d205a4bd5bdc50b973  blocky.initd
3ddd8cd400f9c0f9999430e7fe2507ef5f9ac43bc2e9acbc1bf1b558d383bc891e36a6bf75e2031cd28da69e9dc875f0ac5ad3dac0cf35ce2076651d000e7981  blocky.confd
05f2cae2282a6b36239b012e02978731e28de9af6955315c96257093a24a85713b3abd9f9d1ba3de6452e1bb85e4b8c834dd1aca428b5d7466cc1153c314f667  blocky.example.yml
"
